package com.yuxiu.edu.service.impl;

import com.yuxiu.edu.model.User;
import com.yuxiu.edu.service.IUserService;
import com.yuxiu.edu.service.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl extends BaseServiceImpl<User> implements IUserService{

    @Override
    public User login(String username, String password) {
        return null;
    }

    @Override
    public List<User> findByAll() {
        return userMapper.findAll();
    }
    @Override
    public User findByPassword(String username) {
        return userMapper.findPassword(username);
    }
    public List<User> findByText(String text) {
        return userMapper.selectText(text);
    }
    @Override
    public User findById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public User findByUUID(String uuid) {
        return null;
    }


    @Override
    public void deleteById(Integer id)  {
        userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteByUUID(String uuid) {

    }

    @Override
    public void saveOrUpdate(User user) {

        if(user.getId() ==  null){
            userMapper.insert(user);
            //int i = 10 / 0;
        }else{
            userMapper.updateByPrimaryKeySelective(user);
        }
    }
    @Override
    public void insert(User user) {

    }
}
